// /////////////////////////////////////////////////////////////////////////////
//
// Name:            SoundManager.h
// Author:          Michael Bartsch (ZCCdark203)
//
// Desc :           Declaration of the SoundManager class.
//
// License:         Copyright (C) 2009 Michael Bartsch and Contributors
//
//                  This program is free software: you can redistribute it
//                  and/or modify it under the terms of the zlib/libpng License.
//                  See main.cpp for conditions of distribution and use.
//
// /////////////////////////////////////////////////////////////////////////////

#ifndef __SOUNDMANAGER_H__
#define __SOUNDMANAGER_H__

// Include files
#include "../dependencies.h"
#ifdef __COMPILE_WITH_SFML_AUDIO__
#include "../core/ReferenceCounted.h"

#include "../core/AssetGroup.h"


// SoundManager class
//! The Sound Manager is the central interface point to all sound related functions of this program.
class SoundManager : public ReferenceCounted
{
public:

    // Initialisation and deinitialisation
    //! Constructor
    SoundManager();
    //! Deconstructor
    ~SoundManager();

    //! Initialise the SoundManager.
    void init();
    //! Clears the SoundManager.
    void clear();

    // Reference counting
    //! Increases the reference counter.
    //! @note This is a dummy function.
    void grab();
    //! Decreases the reference counter.
    //! @note This is a dummy function.
    void drop();

    // Methods
    //! Gets the current global volume of all sounds.
    f32 getGlobalVolume() const;
    //! Gets the sound buffer with the given filename.
    //! @param fileName      Name of the buffer to retrieve.
    //! @return Returns the sound buffer on success, else NULL.
    sf::SoundBuffer* getSoundBuffer(const std::string &fileName);

    //! Creates a sound buffer from the given file.
    //! @param fileName      Filename where the buffer should be loaded from.
    bool loadSoundBuffer(const std::string &fileName);
    //! Creates a sound buffer from memory.
    //! @param name          Name of the new sound buffer.
    //! @param buffer        Pointer to the start of the buffer.
    //! @param length        Length of the buffer.
    bool loadSoundBufferFromMemory(const std::string &name, c8 *buffer, long length);

    //! Removes all sound buffers.
    void removeSoundBuffers();
    //! Removes the sound buffer with the given filename.
    //! @param fileName      Name of the buffer to remove.
    bool removeSoundBuffer(const std::string &fileName);

    //! Sets the global volume of all sounds.
    //! @param volume        New global volume.
    void setGlobalVolume(f32 volume);

private:

    std::map<std::string, sf::SoundBuffer*> mSoundBuffers;

};

#endif // __COMPILE_WITH_SFML_AUDIO__

#endif
